package com.yunduan.management.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yunduan.management.entity.News;
import com.yunduan.management.service.NewsService;
import com.yunduan.management.service.PicturesService;
import com.yunduan.management.utils.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @author: hy
 * @date: 2020/11/5 20:35
 * @QQ群: 975366488
 */
@RestController
@CrossOrigin
public class IndexController {
    @Autowired
    private NewsService newsService;
    @Autowired
    private PicturesService picturesService;

    /**
     * 获取首页新闻list
     * @return
     */
    @GetMapping("/IndexNews")
    public JsonObject indexNews(){
        QueryWrapper<News> queryWrapper = new QueryWrapper<>();
        queryWrapper.last("limit 4");
        List<News> newsList = newsService.list(queryWrapper);
        return new JsonObject().success(newsList);
    }

    /**
     * 获取图片列表
     * @return
     */
    @GetMapping("/IndexPictures")
    public JsonObject indexPicture(){
        return new JsonObject().success(picturesService.list());
    }
}
